package com.itheima.mapper;

import com.itheima.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user where username = #{username}")
    public User findByUsername(String username);

    @Select("select * from user where id = #{id}")
    public User findById(Integer id);

    @Select("SELECT * FROM user WHERE username = #{username} OR email = #{email}; ")
    User findByUsernameOrEmail(String username, String email);

    @Insert("insert into user(username,password,email,create_time,update_time) values(#{username},#{password},#{email},now(),now())")
    public void add(String username,String password,String email);

    @Update("update user set nickname = #{nickname},email=#{email},update_time=#{updateTime},role=#{role} where id = #{id}")
    public void update(User user);

    @Update("update user set user_pic = #{avatarUrl},update_time = now() where id = #{id}")
   public void updateAvatar(String avatarUrl, Integer id);

    @Update("update user set password = #{newPwd},update_time = now() where id = #{id}")
    public void updatePwd(String newPwd, Integer id);

    @Select("select * from user")
    List<User> getAllUserInfo();

    List<User> userManage(String username, String nickname, String email);

    @Delete("delete from user where id = #{id}")
    void deleteUser(Integer id);

    @Insert("insert into user(username, nickname, email, role, password,create_time, update_time) values (#{username}, #{nickname}, #{email}, #{role}, #{password},now(), now())")
    void addUser(User user);

    @Select("SELECT * FROM user WHERE email = #{email}")
    User findByEmail(String email);
}
